import rxAjax from '@/assets/js/ajax.js';
import {Util} from '@lowcode/jpaas-base-lib';

const BpmDefApi = {
  baseUrl: '/api-bpm/bpm/core/bpmDef',
  designBaseUrl:'/bpm-designer'  ,
  export:  '/api-bpm/bpm/core/bpmDef/listExport'
}

BpmDefApi.getBpmnXmlFromDefId=function (defId) {
  let url = BpmDefApi.baseUrl + '/getBpmnXmlFromDefId?defId='+defId;
  return rxAjax.get(url);
}
/**
 * 流程定义作废
 * @param defId
 */
BpmDefApi.discard= function (defId){
  let url = BpmDefApi.baseUrl + '/discard';
  return rxAjax.postForm(url,{"defId":defId});
}

/**
 * 流程定义恢复
 * @param defId
 */
BpmDefApi.recover= function (defId){
  let url = BpmDefApi.baseUrl + '/recover';
  return rxAjax.postForm(url,{"defId":defId});
}

// 流程设计导入
BpmDefApi.doImport=function(formData,callback) {
  let url= BpmDefApi.baseUrl+"/doImport";
  return rxAjax.upload(url,formData,callback);
}

/**
 * 流程设计导出
 * @param defIds
 * @returns {*}
 */
BpmDefApi.doExport = function(defIds) {
  defIds=Util.encryptWord(defIds);
  window.location.href='/api/api-bpm/bpm/core/bpmDef/doExport?defIds=' + defIds;
}

/**
 * 获取单记录
 * @param pkId
 * @returns {*}
 */
BpmDefApi.get = function(pkId) {
  let url =  BpmDefApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

BpmDefApi.save =function(parameter) {
  let url=BpmDefApi.baseUrl+ '/save';
  return rxAjax.postJson(url,parameter);
}

BpmDefApi.copyDef=function(parameter){
  let url=BpmDefApi.baseUrl+ '/copyDef';
  return rxAjax.postJson(url,parameter);
}
/**
 * 传入defIds进行流程定义删除
 * @param ids
 */
BpmDefApi.del=function (defIds) {
  let url=BpmDefApi.baseUrl + '/del';
  return rxAjax.postForm(url,{ids:defIds});
}

/**
 * 清除流程运行数据。
 * @param defId
 */
BpmDefApi.clearInstByDefId=function (defId) {
  let url=BpmDefApi.baseUrl + '/clearInstByDefId';
  return rxAjax.postForm(url,{defId:defId});
}

/**
 * 获取流程的开始节点的必填节点与可选节点
 * @param defId
 * @returns {AxiosPromise}
 */
BpmDefApi.getStartUserNodes = function(defId,formData){
  let url=BpmDefApi.baseUrl + '/getStartUserNodes?defId='+ defId;
  return rxAjax.postJson(url,formData);
}

/**
 * 获取流程的开始节点的批次节点
 * @param defId
 * @param formData
 * @returns {*}
 */
BpmDefApi.getBatchUserNodes = function(defId,formData){
  let url=BpmDefApi.baseUrl + '/getBatchUserNodes?defId='+ defId;
  return rxAjax.postJson(url,formData);
}

/**
 * 获取流程的开始节点的批次节点
 * @param instId
 * @returns {*}
 */
BpmDefApi.getBatchUserNodesByInstId = function (instId){
  let url=BpmDefApi.baseUrl + '/getBatchUserNodesByInstId?instId='+instId;
  return rxAjax.get(url);
}


/**
 * 获取流程的开始节点的必填节点与可选节点
 * @param defId
 * @returns {AxiosPromise}
 */
BpmDefApi.getFlowNodesExecutors = function(defId,formData){
  let url=BpmDefApi.baseUrl + '/getFlowNodesExecutors?defId='+ defId;
  return rxAjax.postJson(url,formData);
}


BpmDefApi.saveList=function(parameter){
    var url = BpmDefApi.baseUrl + '/saveList';
    return rxAjax.postJson(url,parameter);
}

BpmDefApi.update = function(parameter){
    let url = BpmDefApi.baseUrl + '/update';
    return rxAjax.postJson(url,parameter);
}

BpmDefApi.getJumpNodes = function(actDefId){
    let url = BpmDefApi.baseUrl + '/getJumpNodes?actDefId=' + actDefId;
    return rxAjax.get(url);
}

BpmDefApi.getNodesByActDefId=function (actDefId){
    let url = BpmDefApi.baseUrl + '/getNodesByActDefId?actDefId=' + actDefId;
    return rxAjax.get(url);
}


BpmDefApi.getBydefKey=function (defKey){
    let url = BpmDefApi.baseUrl + '/getBydefKey?defKey=' + defKey;
    return rxAjax.get(url);
}


BpmDefApi.setBpmCollect=function (defId,isCollect){
    let url = BpmDefApi.baseUrl + '/setBpmDefCollection?defId=' + defId+'&isCollect='+isCollect;
    return rxAjax.get(url);
}
BpmDefApi.getBpmDefCollect=function (){
    let url = BpmDefApi.baseUrl + '/getBpmDefCollection';
    return rxAjax.get(url);
}

BpmDefApi.updExport =function(ids) {
    var url= BpmDefApi.baseUrl + '/updExport';
    return rxAjax.postForm(url,{ids:ids});
}

export default  BpmDefApi;


